home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / postgres / postgre3.z / postgre3 / src / lib / H / access / rulescan.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-27  |  6.0 KB  |  174 lines

  1. /*========================================================================
  2.  *
  3.  * FILE:
  4.  * rulescan.h
  5.  *
  6.  * HEADER:
  7.  * $Header: /private/postgres/src/lib/H/access/RCS/rulescan.h,v 1.5 1991/11/14 11:08:10 glass Exp $
  8.  *
  9.  *-----------------------------------------------------------------------
  10.  * NOTE:
  11.  * -----
  12.  * This file is not supposed to be included directly!
  13.  * Normally all these definitions would habe gone to "prs2.h", but
  14.  * as you can see they use the `EState' defined in "execnodes.h", 
  15.  * which in turn includes "prs2.h", thus creating a circular dependency.
  16.  *
  17.  * And as the "inh" shell scripts are not clever enough to distinguish
  18.  * between a normal typedef (like the ones in this file) and the
  19.  * magic "Class" and "Public" definitions, I decided to create this
  20.  * extra file, is is included in "execnodes.h".
  21.  * If you want to use the structures defined in this file,
  22.  * you must NOT include it directly. Include "execnodes.h" instead!
  23.  *
  24.  *------------------------------------------------------------------------
  25.  *
  26.  *
  27.  * GENERIC RULE INFORMATION FOR A RELATION
  28.  *
  29.  * NOTE: These definitions normally would go to 'prs2.h', but as
  30.  * doing so creates circular dependencies, I decided to put them
  31.  * here.
  32.  *
  33.  * When we retrieve a tuple from a relation we have to call the
  34.  * rule manager. Therfore, in every scan node we have to store some
  35.  * information about rules.
  36.  * So, `CommonScanState' (see execnodes.h) contain a field called
  37.  * 'css_ruleInfo' where all this information is stored.
  38.  * This information should be correctly initialized at the same time the
  39.  * rest of `ScanState' is also initialized (this happens when the
  40.  * executor is called to perform the EXEC_START operation).
  41.  *
  42.  * Similarly when we update a relation (i.e. append. delete or replace a
  43.  * tuple of this relation) we must store some information about the rules
  44.  * defined in this relation (which is called the "result relation").
  45.  * This information is stored in the EState.
  46.  *
  47.  * We use the same structure for both these cases, because they
  48.  * share a lot of information.
  49.  * However some of the fields of this structure apply only to one
  50.  * of these cases and are given null values in the other.
  51.  *
  52.  * The scan state rule information contains the current fields:
  53.  * 
  54.  * ruleList: this is a linked list of records containing information
  55.  *    about all the 'view' like rules, i.e. rules of the form
  56.  *         ON retrieve to <relation>
  57.  *         DO [ instead ] retrieve ......
  58.  *    These rules are processed first by the executor (i.e. before we even
  59.  *     call the access methods for the first time) to retrieve (one by one)
  60.  *    all the tuples returned by the action pat of the rule.
  61.  *    Then if none of these 'view' rules was an "instead" rule, we process
  62.  *    the "real" tuples (the ones returned by the access methods).
  63.  *    
  64.  *    Each record in ruleList can be either a ruleId - plan number pair, 
  65.  *    or a plan (a LispValue) corresponding to a rule (NOTE: each rule
  66.  *    can have more than one plans!) or a query descriptor - EState
  67.  *    pair (in which case we have started retrieving tuples, one by one).
  68.  *    A NULL ruleList means that there are no (more) rules to be processed.
  69.  *
  70.  *    This field only makes sense if we are retrieving tuples from a
  71.  *    relation.
  72.  * 
  73.  * insteadViewRuleFound: True if there was at least one "instead" view
  74.  *    rule was encountered, false otherwise.
  75.  *    This field is only used on retrieve operations.
  76.  *
  77.  * relationLock: the (relation level) rule locks for the scanned
  78.  *    relation (found in the Relation relation)
  79.  *    This is used in both retrieve/update operations.
  80.  *
  81.  * relationStubs: the (relation level) rule stubs.
  82.  *    Normally we would only use them in append & replace operetions
  83.  *    (not on delete and/or retrieves).
  84.  *    But we also have to use them when we run "rule plans"
  85.  *    that add/delete rule locks and/or rule stubs.
  86.  *    These "rule plans" run when import/export locks are broken,
  87.  *    and for the time being they look
  88.  *
  89.  * relationStubsHaveChanged: a boolean flag showing whether
  90.  *    the stubs of a relation have been updated.
  91.  *    This only happens when we run "rule plans" that update
  92.  *    rule locks and/or rule stubs.
  93.  *
  94.  * ignoreTupleLocks: If true, then ignore all the tuple level locks
  95.  *    we'll find in the tuples of this relation.
  96.  *    This is more or less a hack for "pg_class".
  97.  *    Currently we store the relation level locks in the appropriate
  98.  *    tuple of "pg_class". But as the rule manager must not confuse
  99.  *    these locks with tuple level locks of rules defined on "pg_class",
  100.  *    we set this flag whenever the relation we scan is "pg_class".
  101.  *    That of course means that we can not define rules (that use tuple
  102.  *    level locks) on "pg_class", but that's OK....
  103.  */
  104.  
  105. #include "rules/prs2stub.h"
  106.  
  107. #ifndef RuleScan_H
  108. #define RuleScan_H 1
  109.  
  110.  
  111. #define PRS2_RULELIST_RULEID    1
  112. #define PRS2_RULELIST_PLAN    2
  113. #define PRS2_RULELIST_QUERYDESC    3
  114. #define PRS2_RULELIST_DONE    99
  115. #define PRS2_RULELIST_INVALID    100
  116.  
  117. typedef struct Prs2RuleListItem {
  118.     int type;
  119.     struct Prs2RuleListItem *next;
  120.     union {
  121.     struct ruleId {
  122.         ObjectId ruleId;
  123.         Prs2PlanNumber planNumber;
  124.     } ruleId;
  125.     struct rulePlan {
  126.         LispValue plan;
  127.     } rulePlan;
  128.     struct {
  129.         LispValue queryDesc;
  130.         Pointer estate; /* THIS IS AN ESTATE */
  131.     } queryDesc;
  132.     } data;
  133. } Prs2RuleListItem;
  134.  
  135. typedef Prs2RuleListItem *Prs2RuleList;
  136.  
  137. typedef struct RelationRuleInfoData {
  138.     Prs2RuleList ruleList;
  139.     bool insteadViewRuleFound;
  140.     RuleLock relationLocks;
  141.     Prs2Stub relationStubs;
  142.     bool relationStubsHaveChanged;
  143.     bool ignoreTupleLocks;
  144. } RelationRuleInfoData;
  145.  
  146. typedef RelationRuleInfoData *RelationRuleInfo;
  147.  
  148. /*-------------
  149.  * Create and initialize a 'RelationRuleInfo'
  150.  */
  151. extern
  152. RelationRuleInfo
  153. prs2MakeRelationRuleInfo ARGS((
  154.     Relation relation,
  155.     int operation
  156. ));
  157.  
  158. /*-------------
  159.  * Activate the "view" rules & return one by one all the appropriate
  160.  * tuples...
  161.  */
  162. extern
  163. HeapTuple
  164. prs2GetOneTupleFromViewRules ARGS((
  165.     RelationRuleInfo    scanStateRuleInfo,
  166.     Prs2EStateInfo    prs2EStateInfo,
  167.     Relation        relation,           
  168.     Relation        explainRel
  169. ));
  170.  
  171. /*============== END OF RULE_SCAN_INFO DEFINITIONS ======================*/
  172.  
  173. #endif RuleScan_H
  174.